
package sk.lieskove.jianghongtiao.aresapi.response.obj;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.xml.xpath.XPathExpressionException;
import org.apache.log4j.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import sk.lieskove.jianghongtiao.common.utils.xml.ProcessXML;

/**
 * Výpis jednoho subjektu na str. Přehledu
 * 
 * <p>Java class for vypis_osoby complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * &lt;complexType name="vypis_osoby">
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;element name="stav" type="{http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/uvis_datatypes/v_1.0.1}popis" minOccurs="0"/>
 *         &lt;element name="ico" type="{http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/uvis_datatypes/v_1.0.1}ico" minOccurs="0"/>
 *         &lt;element name="Klic_ARES" type="{http://www.w3.org/2001/XMLSchema}int" minOccurs="0"/>
 *         &lt;element name="rc" type="{http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/uvis_datatypes/v_1.0.1}rodne_cislo" minOccurs="0"/>
 *         &lt;element name="ojm" type="{http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/uvis_datatypes/v_1.0.1}obchodni_firma" minOccurs="0"/>
 *         &lt;element name="jmn" type="{http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/uvis_datatypes/v_1.0.1}popis" minOccurs="0"/>
 *         &lt;element name="zdr" type="{http://www.w3.org/2001/XMLSchema}short" minOccurs="0"/>
 *         &lt;element name="ang" type="{http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/uvis_datatypes/v_1.0.1}popis" minOccurs="0"/>
 *         &lt;element name="klic" type="{http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/uvis_datatypes/v_1.0.1}popis" minOccurs="0"/>
 *       &lt;/sequence>
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 * 
 * 
 */
@Entity
@Table(name="ares_vypis_osoby")
public class VypisOsoby implements Serializable {

    @Id
    @GeneratedValue
    private Long id;
    protected String stav;
    protected String ico;
    protected String rc;
    protected String ojm;
    protected String jmn;
    protected String ang;
    protected String klic;
    protected Integer klicARES;
    protected Short zdr;

    @Transient
    private Logger log = Logger.getLogger(ErrorARES.class);
    @Transient
    private String xPath;
    @Transient
    private int index;
    @Transient
    private Document document;
    @ManyToOne
    private VypisStrankyFo vypisStrankyFo;

    public VypisOsoby() {
    }

    VypisOsoby(String xPath, int index, Document document) {
        this.xPath = xPath;
        this.index = index;
        this.document = document;

        setStav();
        setIco();
        setKlicARES();
        setRc();
        setOjm();
        setJmn();
        setZdr();
        setAng();
        setKlic();
    }

    private void setStav(){
        stav = getValue("stav");
    }

    private void setIco(){
        ico = getValue("ico");
    }

    private void setRc(){
        rc = getValue("rc");
    }

    private void setOjm(){
        ojm = getValue("ojm");
    }

    private void setJmn(){
        jmn = getValue("jmn");
    }

    private void setAng(){
        ang = getValue("ang");
    }

    private void setKlic(){
        klic = getValue("klic");
    }

    private void setKlicARES(){
        String val = getValue("Klic_ARES");
        if(val != null){
            klicARES = new Integer(val);
        } else {
            klicARES = null;
        }
    }

    private void setZdr(){
        String val = getValue("zdr");
        if(val != null){
            zdr = new Short(val);
        } else {
            zdr = null;
        }
    }

    private String getValue(String nodeName){
        String xp = xPathConstructor(nodeName);
        log.debug("Loading '"+xp+"'");
        try {
            Node output = ProcessXML.getNodeByXPathQuery(xp, document);
            if (output == null) {
                log.warn("Cannot load: "+xp);
            } else {
                return output.getTextContent();
            }
        } catch (XPathExpressionException ex) {
            log.warn("Cannot load '"+xp+"' property. ",ex);
        }
        return null;
    }

    private String xPathConstructor(String subNode){
        return xPath + "[" + index + "]/" + subNode;
    }

    /**
     * Gets the value of the stav property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getStav() {
        return stav;
    }

    /**
     * Sets the value of the stav property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setStav(String value) {
        this.stav = value;
    }

    /**
     * Gets the value of the ico property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getIco() {
        return ico;
    }

    /**
     * Sets the value of the ico property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setIco(String value) {
        this.ico = value;
    }

    /**
     * Gets the value of the klicARES property.
     * 
     * @return
     *     possible object is
     *     {@link Integer }
     *     
     */
    public Integer getKlicARES() {
        return klicARES;
    }

    /**
     * Sets the value of the klicARES property.
     * 
     * @param value
     *     allowed object is
     *     {@link Integer }
     *     
     */
    public void setKlicARES(Integer value) {
        this.klicARES = value;
    }

    /**
     * Gets the value of the rc property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getRc() {
        return rc;
    }

    /**
     * Sets the value of the rc property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setRc(String value) {
        this.rc = value;
    }

    /**
     * Gets the value of the ojm property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getOjm() {
        return ojm;
    }

    /**
     * Sets the value of the ojm property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setOjm(String value) {
        this.ojm = value;
    }

    /**
     * Gets the value of the jmn property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getJmn() {
        return jmn;
    }

    /**
     * Sets the value of the jmn property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setJmn(String value) {
        this.jmn = value;
    }

    /**
     * Gets the value of the zdr property.
     * 
     * @return
     *     possible object is
     *     {@link Short }
     *     
     */
    public Short getZdr() {
        return zdr;
    }

    /**
     * Sets the value of the zdr property.
     * 
     * @param value
     *     allowed object is
     *     {@link Short }
     *     
     */
    public void setZdr(Short value) {
        this.zdr = value;
    }

    /**
     * Gets the value of the ang property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getAng() {
        return ang;
    }

    /**
     * Sets the value of the ang property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setAng(String value) {
        this.ang = value;
    }

    /**
     * Gets the value of the klic property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getKlic() {
        return klic;
    }

    /**
     * Sets the value of the klic property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setKlic(String value) {
        this.klic = value;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public VypisStrankyFo getVypisStrankyFo() {
        return vypisStrankyFo;
    }

    public void setVypisStrankyFo(VypisStrankyFo vypisStrankyFo) {
        this.vypisStrankyFo = vypisStrankyFo;
    }

}
